package org.csu.goodpartner.controller;

import org.csu.goodpartner.VO.AccountVO;
import org.csu.goodpartner.common.CommonResponse;
import org.csu.goodpartner.entity.Account;
import org.csu.goodpartner.entity.Class;
import org.csu.goodpartner.entity.Shop;
import org.csu.goodpartner.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    //申请商铺
    @PostMapping("/open")
    @ResponseBody
    public CommonResponse<Shop> openShop(@RequestBody AccountVO accountVO)
    {
        int id=accountVO.getId();
        return shopService.openShop(id,accountVO.getEmail(),accountVO.getAddr(),accountVO.getIDcard(),accountVO.getLicense(),accountVO.getName());
    }

    //关闭商铺
    @PostMapping("/close")
    @ResponseBody
    public CommonResponse closeShop(@RequestBody String  id)
    {
        int id1=Integer.valueOf(id).intValue();
        return shopService.deleteShop(id1);
    }
    //查看商铺
    @PostMapping("/all")
    @ResponseBody
    public CommonResponse allShop(@RequestBody String Userid)
    {
        System.out.println(Userid+"aaaaaaaaaaa");
        int id1=Integer.valueOf(Userid).intValue();
        return shopService.allShop(id1);
    }

    //更改分类
    @PostMapping("/updateClass")
    @ResponseBody
    public CommonResponse updateClass(@RequestBody Class classa)
    {
        return shopService.updateClass(classa.getShopid(),classa.getId(),classa.getClassone(),classa.getClasstwo());
    }
    //新增分类
    @PostMapping("/addClass")
    @ResponseBody
    public CommonResponse addClass(@RequestBody Class cla)
    {
        return shopService.addClass(cla.getShopid(), cla.getClassone(), cla.getClasstwo());
    }
    //删除分类
    @PostMapping("/deleteClass")
    @ResponseBody
    public CommonResponse deleteClass(@RequestBody Class classa)
    {
        System.out.println(classa);
//        int shopid1=Integer.valueOf(shopid).intValue();
//        int id1=Integer.valueOf(id).intValue();
        return shopService.deleteClass(classa.getShopid(),classa.getId());
    }
    //更该店铺信息
    @PostMapping("/updateShop")
    @ResponseBody
    public CommonResponse updateClass(@RequestBody Shop shop)
    {
        int shopid1=Integer.valueOf(shop.getShopid()).intValue();
        return shopService.updateShop(shopid1,shop.getName());
    }

    //查询商铺
    @PostMapping("/{shopId}/oneShop")
    @ResponseBody
    public CommonResponse oneShop(@PathVariable(value = "shopId")String id)
    {
        System.out.println(id+"aaaaaaa");
        int id1=Integer.valueOf(id).intValue();
        return shopService.oneShop(id1);
    }

    //所有分类
    @PostMapping("/{shopId}/class")
    @ResponseBody
    public CommonResponse<List<Class>> allClass(@PathVariable(value = "shopId") String id)
    {
        System.out.println(id);
        int id1=Integer.valueOf(id).intValue();
        System.out.println(id1);
        return shopService.allClass(id1);
    }

    //一个分类
    @PostMapping("/{shopId}/oneClass")
    @ResponseBody
    public CommonResponse<Class> oneClass(@PathVariable(value = "shopId") String id)
    {
        System.out.println(id);
        int id1=Integer.valueOf(id).intValue();
        return shopService.oneClass(id1);
    }
}
